package com.tencent.tws.watchfacelib.manager;

import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Handler;
import android.util.Log;
import android.util.SparseArray;
import com.tencent.tws.api.LBSWeatherResult;
import com.tencent.tws.api.healthkit.HealthKitResponse;
import com.tencent.tws.watchfacelib.BroadcastReceiverManager;
import java.util.Calendar;
import java.util.Iterator;
import java.util.Set;

public class BroadcastReceiverCommonService
{
  private static final SparseArray<String[]> DEF_ACTIONS = new SparseArray(7) {};
  public static final int FLAG_DATE_CHANGED = 4;
  public static final int FLAG_RECEIVE_CURRENT_STEP = 1;
  public static final int FLAG_RECEIVE_GOAL_STEP = 2;
  public static final int FLAG_RECEIVE_WEATHERINFO = 100;
  public static final int FLAG_TIMEZONE_CHANGED = 22;
  public static final int FLAG_TIME_CHANGED = 8;
  public static final int FLAG_TIME_TICK = 50;
  private static final String TAG = BroadcastReceiverCommonService.class.getSimpleName();
  private Set<String> customActions;
  private int flag = 0;
  private ResponseListener listener;
  private Context mContext;
  Calendar preCalendar = Calendar.getInstance();
  private final BroadcastReceiverManager receiver;
  
  public BroadcastReceiverCommonService(Context paramContext)
  {
    this.mContext = paramContext;
    this.receiver = new BroadcastReceiverManager(paramContext)
    {
      private static final int MULTI_FIRED_TIME_CHECK = 300;
      final Handler handler = new Handler();
      boolean isDateChangedJustFired = false;
      boolean isTimeChangedJustFired = false;
      Runnable resetDateChangeState = new Runnable()
      {
        public void run()
        {
          isDateChangedJustFired = false;
        }
      };
      Runnable resetTimeChangeState = new Runnable()
      {
        public void run()
        {
          isTimeChangedJustFired = false;
        }
      };
      
      public void onReceive(Context paramAnonymousContext, Intent paramAnonymousIntent)
      {
        Log.d(BroadcastReceiverCommonService.TAG, "onReceive:" + paramAnonymousIntent.getAction());
        if ("android.intent.action.DATE_CHANGED".equals(paramAnonymousIntent.getAction())) {
          if ((BroadcastReceiverCommonService.this.isFlagSet(4, BroadcastReceiverCommonService.this.flag)) && (BroadcastReceiverCommonService.this.listener != null) && (!this.isDateChangedJustFired))
          {
            this.isDateChangedJustFired = true;
            this.handler.postDelayed(this.resetDateChangeState, 300L);
            BroadcastReceiverCommonService.this.listener.onDateChanged();
          }
        }
        do
        {
          do
          {
            do
            {
              do
              {
                do
                {
                  do
                  {
                    do
                    {
                      do
                      {
                        do
                        {
//                          return;
                          if ((!"android.intent.action.TIME_SET".equals(paramAnonymousIntent.getAction())) && (!"Action.Tws.WatchTimeChanged".equals(paramAnonymousIntent.getAction()))) {
                            break;
                          }
                          if ((BroadcastReceiverCommonService.this.isFlagSet(8, BroadcastReceiverCommonService.this.flag)) && (BroadcastReceiverCommonService.this.listener != null) && (!this.isTimeChangedJustFired))
                          {
                            this.isTimeChangedJustFired = true;
                            this.handler.postDelayed(this.resetTimeChangeState, 300L);
                            BroadcastReceiverCommonService.this.listener.onTimeChanged();
                          }
                        } while ((!BroadcastReceiverCommonService.this.isFlagSet(4, BroadcastReceiverCommonService.this.flag)) || (BroadcastReceiverCommonService.this.listener == null) || (!BroadcastReceiverCommonService.this.isDateChanged()) || (this.isDateChangedJustFired));
                        this.isDateChangedJustFired = true;
                        this.handler.postDelayed(this.resetDateChangeState, 300L);
                        BroadcastReceiverCommonService.this.listener.onDateChanged();
//                        return;
                        if (!"android.intent.action.TIMEZONE_CHANGED".equals(paramAnonymousIntent.getAction())) {
                          break;
                        }
                      } while ((!BroadcastReceiverCommonService.this.isFlagSet(22, BroadcastReceiverCommonService.this.flag)) || (BroadcastReceiverCommonService.this.listener == null));
                      BroadcastReceiverCommonService.this.listener.onTimeZoneChanged();
//                      return;
                      if (!"Action.Tws.StepGoal".equals(paramAnonymousIntent.getAction())) {
                        break;
                      }
                    } while ((!BroadcastReceiverCommonService.this.isFlagSet(2, BroadcastReceiverCommonService.this.flag)) || (BroadcastReceiverCommonService.this.listener == null));
                    int i = paramAnonymousIntent.getIntExtra("StepGoal", 10000);
                    BroadcastReceiverCommonService.this.listener.onReceiveGoalStep(null, i);
//                    return;
                    if (!"Action.response.healthkit".equals(paramAnonymousIntent.getAction())) {
                      break;
                    }
                  } while ((!BroadcastReceiverCommonService.this.isFlagSet(1, BroadcastReceiverCommonService.this.flag)) || (BroadcastReceiverCommonService.this.listener == null));
//                  paramAnonymousContext = (HealthKitResponse)paramAnonymousIntent.getParcelableExtra("healthKitResponse");
                  if (paramAnonymousContext == null)
                  {
                    Log.e(BroadcastReceiverCommonService.TAG, "HealthKitResponse data is null");
                    return;
                  }
//                  int i = HealthKitServiceManager.ParseHealthKitResponseStep(paramAnonymousContext);
                  int i = 0;
                  BroadcastReceiverCommonService.this.listener.onReceiveCurrentStep(paramAnonymousContext, i);
//                  return;
                  if (!"android.intent.action.TIME_TICK".equals(paramAnonymousIntent.getAction())) {
                    break;
                  }
                  if ((BroadcastReceiverCommonService.this.isFlagSet(50, BroadcastReceiverCommonService.this.flag)) && (BroadcastReceiverCommonService.this.listener != null)) {
                    BroadcastReceiverCommonService.this.listener.onTimeTicked();
                  }
                } while ((!BroadcastReceiverCommonService.this.isFlagSet(4, BroadcastReceiverCommonService.this.flag)) || (BroadcastReceiverCommonService.this.listener == null) || (!BroadcastReceiverCommonService.this.isDateChanged()) || (this.isDateChangedJustFired));
                this.isDateChangedJustFired = true;
                this.handler.postDelayed(this.resetDateChangeState, 300L);
                BroadcastReceiverCommonService.this.listener.onDateChanged();
//                return;
                if (!"Action.Tws.LbsGetWeatherResult".equals(paramAnonymousIntent.getAction())) {
                  break;
                }
              } while ((!BroadcastReceiverCommonService.this.isFlagSet(100, BroadcastReceiverCommonService.this.flag)) || (BroadcastReceiverCommonService.this.listener == null));
//              paramAnonymousContext = (LBSWeatherResult)paramAnonymousIntent.getParcelableExtra("Result");
            } while (paramAnonymousContext == null);
//            paramAnonymousContext = paramAnonymousContext.getWeatherInfos();
//          } while ((paramAnonymousContext == null) || (paramAnonymousContext.length <= 0));
          } while ((paramAnonymousContext == null));
//          BroadcastReceiverCommonService.this.listener.onReceiveWeatherInfo(paramAnonymousContext, paramAnonymousContext[0]);
//          return;
        } while ((BroadcastReceiverCommonService.this.listener == null) || (BroadcastReceiverCommonService.this.customActions == null) || (!BroadcastReceiverCommonService.this.customActions.contains(paramAnonymousIntent.getAction())));
        BroadcastReceiverCommonService.this.listener.onCustomActionFired(paramAnonymousContext, paramAnonymousIntent);
      }
    };
  }
  
  private IntentFilter getIntentFilters()
  {
    IntentFilter localIntentFilter = new IntentFilter();
    if (isFlagSet(4, this.flag))
    {
      localIntentFilter.addAction("android.intent.action.TIME_TICK");
      localIntentFilter.addAction("android.intent.action.DATE_CHANGED");
    }
    if (isFlagSet(8, this.flag))
    {
      localIntentFilter.addAction("android.intent.action.TIME_SET");
      localIntentFilter.addAction("Action.Tws.WatchTimeChanged");
    }
    if (isFlagSet(22, this.flag)) {
      localIntentFilter.addAction("android.intent.action.TIMEZONE_CHANGED");
    }
    if (isFlagSet(50, this.flag)) {
      localIntentFilter.addAction("android.intent.action.TIME_TICK");
    }
    if (isFlagSet(2, this.flag)) {
      localIntentFilter.addAction("Action.Tws.StepGoal");
    }
    if (isFlagSet(1, this.flag)) {
      localIntentFilter.addAction("Action.response.healthkit");
    }
    if ((this.customActions == null) || (this.customActions.size() <= 0)) {}
    for (;;)
    {
//      return localIntentFilter;
      Iterator localIterator = this.customActions.iterator();
      while (localIterator.hasNext()) {
        localIntentFilter.addAction((String)localIterator.next());
      }
    }
  }
  
  private boolean isDateChanged()
  {
    Calendar localCalendar = Calendar.getInstance();
    if ((localCalendar.get(Calendar.YEAR) != this.preCalendar.get(Calendar.YEAR)) || (localCalendar.get(Calendar.DAY_OF_YEAR) != this.preCalendar.get(Calendar.DAY_OF_YEAR)))
    {
      this.preCalendar = localCalendar;
      return true;
    }
    return false;
  }
  
  private boolean isFlagSet(int paramInt1, int paramInt2)
  {
    return (paramInt1 & paramInt2) == paramInt1;
  }
  
  private boolean registerBroadcast()
  {
    if (this.mContext == null) {}
    while (this.flag == 0) {
      return false;
    }
    this.receiver.registerReceiver(getIntentFilters());
    return true;
  }
  
  public boolean register(int paramInt, ResponseListener paramResponseListener)
  {
    return register(paramInt, null, paramResponseListener);
  }
  
  public boolean register(int paramInt, Set<String> paramSet, ResponseListener paramResponseListener)
  {
    this.flag = paramInt;
    this.listener = paramResponseListener;
    this.customActions = paramSet;
    return registerBroadcast();
  }
  
  public boolean unregister()
  {
    if (this.receiver == null) {
      return false;
    }
    return this.receiver.unregisterReceiver();
  }
  
  public static abstract interface ResponseListener
  {
    public abstract void onCustomActionFired(Context paramContext, Intent paramIntent);
    
    public abstract void onDateChanged();
    
    public abstract void onReceiveCurrentStep(Object paramObject, int paramInt);
    
    public abstract void onReceiveGoalStep(Object paramObject, int paramInt);
    
    public abstract void onReceiveWeatherInfo(Object paramObject1, Object paramObject2);
    
    public abstract void onTimeChanged();
    
    public abstract void onTimeTicked();
    
    public abstract void onTimeZoneChanged();
  }
}


/* Location:              G:\zyl\ylwork\Android\Android_Decode\apk2java\apktool2.1.0\WatchFaceSports\classes-dex2jar.jar!\com\tencent\tws\watchfacelib\manager\BroadcastReceiverCommonService.class
 * Java compiler version: 6 (50.0)
 * JD-Core Version:       0.7.1
 */